import java.util.Arrays;
import java.util.EmptyStackException;

public class MyStack {
    public int[] elem;
    public int useSize;

    public MyStack(int[] elem) {
        this.elem = elem;
    }

    //判满
    public boolean isFull(){
        if (elem.length == useSize){
            return true;
        }
        return false;
    }

    //判空
    public boolean isEmpty(){
        if (elem.length == 0){
            return true;
        }
        return false;
    }


    //进栈
    public void push(int val){
        if (isFull()){
            elem = Arrays.copyOf(elem, 2*elem.length);
        }
        elem[useSize++] =val;
    }

    //出栈
    public int pop() {
        if (isEmpty()){
            throw new EmptyException("栈空，pop失败");
        }

        return elem[--useSize];
    }

}
